

using System.Linq;
using Abp.Authorization;
using Abp.Configuration.Startup;
using Abp.Localization;
using Abp.MultiTenancy;
using LTMCompanyName.YoyoCmsTemplate.Authorization;

// ReSharper disable once CheckNamespace
namespace LTMCompanyName.YoyoCmsTemplate.Exam.Authorization
{
    /// <summary>
    /// 权限配置都在这里。
    /// 给权限默认设置服务
    /// See <see cref="StockCategoryPermissions" /> for all permission names. StockCategory
    ///</summary>
    public class StockCategoryAuthorizationProvider : AuthorizationProvider
    {
        private readonly bool _isMultiTenancyEnabled;

        public StockCategoryAuthorizationProvider()
        {

        }


        public StockCategoryAuthorizationProvider(bool isMultiTenancyEnabled)
        {
            _isMultiTenancyEnabled = isMultiTenancyEnabled;
        }

        public StockCategoryAuthorizationProvider(IMultiTenancyConfig multiTenancyConfig)
        {
            _isMultiTenancyEnabled = multiTenancyConfig.IsEnabled;
        }

        public override void SetPermissions(IPermissionDefinitionContext context)
        {
            // 在这里配置了College 的权限。
            var pages = context.GetPermissionOrNull(AppLtmPermissions.Pages) ?? context.CreatePermission(AppLtmPermissions.Pages, L("Pages"));

            var administration = pages.Children.FirstOrDefault(p => p.Name == AppLtmPermissions.Pages_Exam) ?? pages.CreateChildPermission(AppLtmPermissions.Pages_Exam, L("Pages_Exam"));

            var stockCategory = administration.CreateChildPermission(StockCategoryPermissions.StockCategory_Node, L("StockCategory"));
            stockCategory.CreateChildPermission(StockCategoryPermissions.StockCategory_Query, L("QueryStockCategory"));
            stockCategory.CreateChildPermission(StockCategoryPermissions.StockCategory_Create, L("CreateStockCategory"));
            stockCategory.CreateChildPermission(StockCategoryPermissions.StockCategory_Edit, L("EditStockCategory"));
            stockCategory.CreateChildPermission(StockCategoryPermissions.StockCategory_Delete, L("DeleteStockCategory"));
            stockCategory.CreateChildPermission(StockCategoryPermissions.StockCategory_BatchDelete, L("BatchDeleteStockCategory"));
            stockCategory.CreateChildPermission(StockCategoryPermissions.StockCategory_ExportExcel, L("ExportToExcel"));


            //// custom codes

            //// custom codes end
        }

        private static ILocalizableString L(string name)
        {
            return new LocalizableString(name, AppConsts.LocalizationSourceName);
        }
    }
}
